<!--骑手列表-配送状况-->
<template>
  <div class="video-list-manage-parent" ref="parentContainer">
    <!--操作表单区域-->
    <div class="option-parent" ref="optionParentContainer">
      <el-row :gutter="0">
        <el-col :span="6">
          <el-date-picker
            v-model="dt1"
            type="datetime"
            style="width: 100%"
            placeholder="起止日期">
          </el-date-picker>
        </el-col>
        <el-col :span="6">
          <el-date-picker
            v-model="dt2"
            type="datetime"
            style="width: 100%"
            placeholder="结束日期">
          </el-date-picker>
        </el-col>
        <el-col :span="8">
          <el-button type="primary" @click="queryArticleByBtn()">查询</el-button>
          <el-button type="primary" @click="exportDataList()">下载</el-button>
        </el-col>
        <el-col :span="4">
        </el-col>
      </el-row>
    </div>

    <!--数据表格区域-->
    <div v-bind:style="{height:tableHeight+'px',width:'100%'}" v-loading="loading">
      <el-table :data="orderData.agent_deliver_summary_list" border width="100%" height="100%">
        <el-table-column
          fixed
          prop="dt"
          label="日期"
          min-width="110">
        </el-table-column>
        <el-table-column
          prop="areaname"
          label="分区"
          min-width="100">
        </el-table-column>
        <el-table-column
          prop="sellers"
          label="商户数量"
          min-width="100">
        </el-table-column>
        <el-table-column
          prop="riders"
          label="骑手数量"
          min-width="100">
        </el-table-column>
        <el-table-column
          prop="day_rider"
          label="白班骑手数量"
          min-width="100">
        </el-table-column>
        <el-table-column
          prop="day_deliver"
          label="配送次数"
          min-width="100">
        </el-table-column>
        <el-table-column
          prop="day_avg"
          label="平均配送次数"
          min-width="100">
        </el-table-column>
        <el-table-column
          prop="night_rider"
          label="晚班骑手数量"
          min-width="100">
        </el-table-column>
        <el-table-column
          prop="night_deliver"
          label="配送次数"
          min-width="100">
        </el-table-column>
        <el-table-column
          prop="night_avg"
          label="平均配送次数"
          min-width="100">
        </el-table-column>
        <!--<el-table-column label="操作" min-width="150">-->
        <!--<template slot-scope="scope">-->
        <!--<el-button-->
        <!--size="mini"-->
        <!--type="danger"-->
        <!--@click="handleSellerWiner(scope.row)">-->
        <!--商家胜-->
        <!--</el-button>-->
        <!--<el-button-->
        <!--size="mini"-->
        <!--type="danger"-->
        <!--@click="handleUserWiner(scope.row)">-->
        <!--用户胜-->
        <!--</el-button>-->
        <!--</template>-->
        <!--</el-table-column>-->
      </el-table>
    </div>

    <!--翻页区域-->
    <div class="pagination-parent" ref="paginationParentContainer">
      <el-pagination
        class="pagination-body"
        @current-change="handleCurrentChange"
        :page-size="limit"
        layout="total, prev, pager, next"
        :total="orderData.rowcount">
      </el-pagination>
    </div>

  </div>
</template>

<script>
  import CPageBase from "../fragment/CPageBase"
  import CRootBase from "../fragment/CRootBase"

  export default {
    data() {
      return {
        pathArr: [
          {path: "/", name: "首页"},
          {path: "/container/rider_distri_state", name: "配送状况"},
        ],
        start: 1,
        limit: 20,
        orderData: "",
        loading: false,
        dt1: '',
        dt2: ''
      }
    },
    watch: {},
    mixins: [CPageBase, CRootBase],
    components: {},
    mounted() {

    },
    activated() {
      this.initCurrentPath();
      this.requestOrderData();
    },
    methods: {
      //初始化面包屑路径
      initCurrentPath() {
        this.$store.commit('changeCurrentLocation', this.pathArr);
      },

      //计算班次
      genBanCi(item) {
        if (item === "0") {
          return "白班";
        } else if (item === "1") {
          return "夜班";
        }
      },

      //拼接图片地址
      genColumnImg(item) {
        return this.$utils.genImgURL(item.url);
      },

      //截取时间
      genTime(time) {
        return time.substring(0, time.length - 2);
      },

      //打开新增页面
      openPage() {
        this.$router.push("seller_add");
      },

      //打开编辑页
      handleEdit(item) {

      },


      // 导出数据
      exportDataList () {
        let url=this.$http.getDownLoadUrl(this,'agent_deliver_summary_list');
        url =url +'&dt1=' +this.$utils.getTimeDt(this.dt1) +'&dt2='+this.$utils.getTimeDt(this.dt2);
        window.open(url);
      },

      //处理页面改变事件
      handleCurrentChange(currentPage) {
        this.start = this.start + this.limit;
        this.requestOrderData();
      },

      //点击查询按钮
      queryArticleByBtn() {
        this.start = 1;
        this.limit = 20;
        this.requestOrderData();
      },

      //转换时间格式
      getTimeDt(dt, sign) {
        let nowDate = "";
        if (this.$utils.isEmpty(dt) && sign === 1) {
          nowDate = new Date();
          nowDate.setMonth(nowDate.getMonth() - 1);
        } else if (this.$utils.isEmpty(dt)) {
          nowDate = new Date();
        } else {
          nowDate = new Date(dt);
        }
        let year1 = nowDate.getFullYear();
        let month1 = nowDate.getMonth() + 1;
        let date1 = nowDate.getDate();
        let hours1 = nowDate.getHours();
        let minutes1 = nowDate.getMinutes();
        let millis1 = nowDate.getMilliseconds();
        if (month1 < 10) {
          month1 = "0" + month1;
        }
        if (date1 < 10) {
          date1 = "0" + date1;
        }
        if (hours1 < 10) {
          hours1 = "0" + hours1;
        }
        if (minutes1 < 10) {
          minutes1 = "0" + minutes1;
        }
        if (millis1 < 10) {
          millis1 = "0" + millis1;
        }
        millis1 = millis1 + "".substring(0, 1);
        return year1 + "-" + month1 + "-" + date1 + " " + hours1 + ":" + minutes1 + ":" + millis1;
      },

      //获取订单
      requestOrderData() {
        let parameter = new URLSearchParams();
        parameter.append("action", "agent_deliver_summary_list");
        parameter.append("pageno", this.start);
        parameter.append("pagesize", this.limit);
        parameter.append('dt1', this.$utils.getTimeDt(this.dt1));
        parameter.append('dt2', this.$utils.getTimeDt(this.dt2));
        let that = this;
        that.loading = true;
        this.$http.requestAuthData(that, parameter, function (data) {
          that.orderData = data;
        });
      },

      //商家胜出提示框
      handleSellerWiner(item,) {
        let that = this;
        this.$confirm('确认商家在本轮裁决胜出吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          that.confireWhoWiner(item, 1);
        }).catch(() => {
        });
      },

      //用户胜出提示框
      handleUserWiner(item,) {
        let that = this;
        this.$confirm('确认用户在本轮裁决胜出吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          that.confireWhoWiner(item, 0);
        }).catch(() => {
        });
      },

      //裁决请求
      confireWhoWiner(item, sign) {
        let that = this;
        let parameter = new URLSearchParams();
        parameter.append("action", "agent_order_judge");
        parameter.append("orderid", item.orderid);
        parameter.append("judge_state", sign);
        that.loading = true;
        this.$http.requestAuthData(that, parameter, function (data) {
          that.$message({type: 'success', message: '裁决成功!'});
          that.requestOrderData();
        });
      },
    }
  }
</script>

<style lang="scss" scoped="" type="text/scss" src="../../assets/style/list-type-pages.scss">

</style>

